package com.wuba.rxjavademo.lyz.day0614;

import com.wuba.rxjavademo.lyz.BaseDemo;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * Created by liyaxing on 2016/6/17.
 */
public class Demo02 extends BaseDemo {

    public static void main(String[] ss){
        Observable.just(1)
                .doOnNext(new Action1<Integer>() {
                    @Override
                    public void call(Integer integer) {
                        print("[doOnNext]");
                    }
                })
                .map(new Func1<Integer, Integer>() {
                    @Override
                    public Integer call(Integer integer) {
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        return 2;
                    }
                })
                .subscribe(new Subscriber<Integer>() {
                    @Override
                    public void onCompleted() {
                        print("[onCompleted]");
                    }

                    @Override
                    public void onError(Throwable e) {
                        print("[onError]");
                    }

                    @Override
                    public void onNext(Integer integer) {
                        print("[onNext]");
                    }
                }) ;
    }

}
